package com.xiaodao.springboot.utility;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.nio.file.Path;

public class ObjectSerializer {
    private static final ObjectMapper mapper = new ObjectMapper();

    public static <T> void writeToFile(T obj, Path path) throws IOException {
        mapper.writeValue(path.toFile(), obj);
    }

    public static <T> T readFromFile(Path path, Class<T> type) throws IOException {
        return mapper.readValue(path.toFile(), type);
    }
}